package com.ticket.sass.admin.controller;


import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import com.ticket.sass.admin.business.RoleBusiness;
import com.ticket.sass.admin.business.impl.RoleBusinessImpl;
import com.ticket.sass.admin.dto.input.role.RoleAddInput;
import com.ticket.sass.admin.dto.input.role.RoleListInput;
import com.ticket.sass.admin.dto.input.role.RolePowerSaveInput;
import com.ticket.sass.admin.dto.input.role.RoleUpdInput;
import com.ticket.sass.admin.dto.output.role.RoleListOutput;
import com.ticket.sass.admin.model.PageModel;
import com.ticket.sass.admin.model.ResultModel;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;


/**
 * 角色控制层
 * @author ywb
 * @since 2021-10-07
 */
@Slf4j
@RestController
@ApiSupport(order = 902)
@Api(tags = "角色-模块")
@RequestMapping("/role")
public class RoleController {
    final RoleBusiness business;

    public RoleController(RoleBusinessImpl business) {
        this.business = business;
    }
    
    @GetMapping
    @ApiOperation(value = "角色列表", notes = "根据页面参数查询角色信息列表")
    public ResultModel<PageModel<RoleListOutput>> getFyRoles(
        @Valid RoleListInput input
    ) {
        return ResultModel.success(
            business.list(input)
        );
    }

    @ApiOperation(value = "新增角色", notes = "根据ID确定是否存在角色信息，进行新增或修改")
    @PostMapping
    public ResultModel<String> saveRole(
        @RequestBody @Valid RoleAddInput input
    ) {
        business.add(input);
        return ResultModel.success();
    }

    @ApiOperation(value = "修改角色", notes = "根据角色 ID 修改角色")
    @PutMapping
    public ResultModel<String> delRole(
        @RequestBody @Valid RoleUpdInput input
    ) {
        business.upd(input);
        return ResultModel.success();
    }
    
    @ApiOperation(value = "保存角色权限", notes = "设置角色权限")
    @PostMapping("/savePower")
    public ResultModel<String> savePower(
        @RequestBody @Valid RolePowerSaveInput input
    ) {
        business.savePower(input);
        return ResultModel.success();
    }
}